this._surroundingText = null;
this._surroundingTextCursor = null;
+ this._surroundingTextAnchor = null;
this._preeditStr = null;
this._setTerminalMode(false);
}
vfunc_set_surrounding(text, cursor, anchor) {
this._surroundingText = text;
this._surroundingTextCursor = cursor;
+ this._surroundingTextAnchor = anchor;
this.emit('surrounding-text-set');
if (!this._context || (!text && text !== ''))
}
getSurroundingText() {
- return [this._surroundingText, this._surroundingTextCursor];
+ return [
+ this._surroundingText,
+ this._surroundingTextCursor,
+ this._surroundingTextAnchor,
+ ];
}
hasPreedit() {
}
if (enabled) {
- let func = (text, cursor) => {
- if (cursor === 0)
+ let func = (text, cursor, anchor) => {
+ if (cursor === 0 && anchor === 0)
return;
- const anchor = this._timesDeleted < BACKSPACE_WORD_DELETE_THRESHOLD
- ? cursor - 1
- : this._previousWordPosition(text, cursor);
- const offset = anchor - cursor;
+ let offset, len;
+ if (cursor > anchor) {
+ offset = anchor - cursor;
+ len = -offset;
+ } else if (cursor < anchor) {
+ offset = 0;
+ len = anchor - cursor;
+ } else if (this._timesDeleted < BACKSPACE_WORD_DELETE_THRESHOLD) {
+ offset = -1;
+ len = 1;
+ } else {
+ const wordLength = cursor - this._previousWordPosition(text, cursor);
+ offset = -wordLength;
+ len = wordLength;
+ }
this._timesDeleted++;
- Main.inputMethod.delete_surrounding(offset, Math.abs(offset));
+ Main.inputMethod.delete_surrounding(offset, len);
};
this._surroundingUpdateId = Main.inputMethod.connect(
'surrounding-text-set', () => {
- let [text, cursor] = Main.inputMethod.getSurroundingText();
+ let [text, cursor, anchor] = Main.inputMethod.getSurroundingText();
if (this._timesDeleted === 0) {
- func(text, cursor);
+ func(text, cursor, anchor);
} else {
if (this._surroundingUpdateTimeoutId > 0) {
GLib.source_remove(this._surroundingUpdateTimeoutId);
}
this._surroundingUpdateTimeoutId =
GLib.timeout_add(GLib.PRIORITY_DEFAULT, KEY_RELEASE_TIMEOUT, () => {
- func(text, cursor);
+ func(text, cursor, cursor);
this._surroundingUpdateTimeoutId = 0;
return GLib.SOURCE_REMOVE;
});
}
});
- let [text, cursor] = Main.inputMethod.getSurroundingText();
+ let [text, cursor, anchor] = Main.inputMethod.getSurroundingText();
if (text)
- func(text, cursor);
+ func(text, cursor, anchor);
else
Main.inputMethod.request_surrounding();
} else {